<template>
	<view class="coupon">
		<view class="tabBox">
			<u-subsection :list="tabList" :current="current" active-color="#fe0000" @change="sectionChange"></u-subsection>
		</view>
		
		<view class="listBox" :class="current==0?'':'invalidation'">
			<block v-for="(item,index) in this_data_list">
			<view class="item">
				<view class="left" v-if="item.q_type != 3">
					<view class="amount">{{item.q_diyong_jiner}}<text class="text">元</text></view>
					<view class="limit">{{item.use_limit_text}}</view>
				</view>
				<view class="left" v-if="item.q_type == 3">
					<view class="amount">免费</view>
				</view>
				<view class="center">
					<view class="title">{{item.q_name}}</view>
					<view class="time">有效期：{{item.use_time_text}}</view>
				</view>
				<button v-if="item.q_status==0" @click="go_home" type="default" size="mini" class="btn">立即使用</button>
				<image v-if="item.q_status==1" class="img"  src="../static/expired.png" mode="widthFix"></image>
				<image v-if="item.q_status==2" class="img"  src="../static/old.png" mode="widthFix"></image>
			</view>
			</block>
		</view>
		<view class="noContent" v-if="this_data_list.length == 0">
		  <image class="noContentImage" mode="widthFix" src="/static/noLive.png"></image>
		</view>
	</view>
</template>

<script>
	var util = require('../../common/util.js');
	export default {
		data() {
			return {
				tabList: [
					{
						name: '可使用'
					}, 
					{
						name: '已失效'
					}
				],
				current: 0,
				this_data_list:[],
				this_select_type:0,
				this_pagesize:1,
				this_pagenum:20,
				isMore:true
			}
		},
		onLoad() {
			this.get_index_data();
		},
		methods: {
			sectionChange(index) {
				this.current = index;
				this.this_select_type = index;
				this.this_pagesize = 1;
				this.isMore = true;
				this.this_data_list = [];
				this.get_index_data();
			},
			get_index_data:function(){
				let _this = this;
				const param = {};
				param.pagesize = _this.this_pagesize;
				param.pagenum = _this.this_pagenum;
				param.select_type = _this.this_select_type;
				util.requestPost('api.php/UserCoupon/getUserCouponList',param,function(res) {
						if(res.data.this_data_list.length >= _this.this_pagenum){
							_this.this_pagesize = _this.this_pagesize + 1;
							_this.isMore = true;
						}else{
							_this.isMore = false;
						}
						if(_this.this_data_list.length > 0){
							_this.this_data_list = _this.this_data_list.concat(res.data.this_data_list);
						}else{
							_this.this_data_list = res.data.this_data_list;
						}
					}
				);
			},
			onReachBottom:function(){
				let _this = this;
				if(_this.isMore == true) _this.get_index_data();
			},
			go_home:function(){
				uni.switchTab({
					url:"/pages/index/index"
				})
			}
		}
	}
</script>

<style scoped lang="scss">
.coupon {
	min-height: 100%;
	background-color: var(--bgColor);
}
.tabBox {
	padding: 12rpx 24rpx;
	background-color: #FFFFFF;
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
}
.listBox {
	padding: 114rpx 24rpx 24rpx;
	.item {
		border-radius: 12rpx;
		background-color: #FFFFFF;
		padding: 24rpx 24rpx 24rpx 12rpx;
		border: 1rpx solid #bbbbbb;
		box-shadow: 0 4rpx 0 rgba($color: #ddd, $alpha: 1.0);
		display: flex;
		align-items: flex-end;
		margin-bottom: 20rpx;
		&:last-of-type {
			margin-bottom: 0;
		}
		.left {
			width: 180rpx;
			text-align: center;
			margin-right: 12rpx;
			.amount {
				font-size: 48rpx;
				font-weight: bold;
				color: var(--primaryColor);
				.text {
					font-size: 24rpx;
					font-weight: normal;
				}
			}
			.limit {
				font-size: 24rpx;
				color: #999999;
				margin-top: 8rpx;
			}
		}
		.center {
			flex: 1;
			.title {
				font-size: 32rpx;
				font-weight: bold;
			}
			.time {
				font-size: 24rpx;
				color: #999999;
				margin-top: 8rpx;
			}
		}
		.btn {
			font-size: 24rpx;
			color: var(--primaryColor);
			border: 1rpx solid var(--primaryColor);
			border-radius: 80rpx;
			background-color: transparent;
			margin-left: 12rpx;
			&::after {
				border: none;
			}
		}
	}
	&.invalidation {
		.item {
			position: relative;
			overflow: hidden;
			.left {
				.amount {
					color: #999999;
				}
			}
			.center {
				.title {
					color: #999999;
				}
			}
			.img {
				width: 120rpx;
				position: absolute;
				right: -16rpx;
				bottom: -16rpx;
			}
		}
	}
}
</style>
